//
// Created by Win10 on 2022/10/30.
//
#include<iostream>
#include "sql_queue.h"

using namespace std;

void InitQueue(LinkQueue &Q) {
    Q.front = Q.rear = nullptr;
}

bool QueueEmpty(LinkQueue Q) {
    if (Q.front == nullptr) return true;
    return false;
}

bool EnQueue(LinkQueue &Q, ElemType x) {
    auto *s = (LinkNode *) malloc(sizeof(LinkNode));
    s->data = x;
    s->next = nullptr;
    if (QueueEmpty(Q)) {
        Q.front = Q.rear = s;
    } else {
        Q.rear->next = s;
        Q.rear = s;
    }
    return true;
}

bool DeQueue(LinkQueue &Q, ElemType &x) {
    if (QueueEmpty(Q)) {
        return false;
    }
    LinkNode *s = Q.front;
    x = s->data;
    if (Q.rear == s) {
        Q.front = Q.rear = nullptr;
    } else {
        Q.front = s->next;
    }
    free(s);
    return true;
}

bool GetHead(LinkQueue Q, ElemType &x) {
    if (QueueEmpty(Q)) return false;
    x = Q.front->data;
    return true;
}


int main() {
    {
        LinkQueue Q;
        InitQueue(Q);
        for (int i = 1; i <= 5; i++) {
            EnQueue(Q, i);
        }
        ElemType x;
        GetHead(Q, x);
        cout << x << endl << endl;
        while (!QueueEmpty(Q)) {
            DeQueue(Q, x);
            cout << x << endl;
        }
    }
    return 0;
}